package utils

import (
	"crypto/md5"
	"fmt"
	"io"
)

func CalculateFileHash(r io.Reader) string {
	h := md5.New()
	if _, err := io.Copy(h, r); err != nil {
		return ""
	}
	bytStr := fmt.Sprintf("%x", h.Sum(nil))
	return bytStr
}

func GetFileExtension(filename string) string {
	for i := len(filename) - 1; i >= 0 && filename[i] != '.'; i-- {
		if i == 0 {
			return ""
		}
	}
	return filename[len(filename)-3:]
}
